|
|
|
|
|
|
|
intRecs = rs.RecordCount ' get count
MsgBox strRSName & " :" & CStr(intRecs), vbInformation, "Total Records in
Set"
'
End Sub |
|
|
|
|
|
|
|
|
Now that you have the object and the variable (marked with <<< in Listing 3.5), you can add code that creates a new Recordset. First you set the Filter property of the existing Recordset using the variable you just created. Then you create the new Recordset from the old one. See the last two lines of the code in Listing 3.6. |
|
|
|
|
|
|
|
|
Listing 3.6. Using the Filter property to create a Recordset. |
|
|
|
|
|
|
|
|
Private Sub Form_Load()
'
' creating dynaset-type recordsets
'
Dim db As Database ' the database object
Dim rs As Recordset ' the recordset object
Dim rs2 As Recordset ' another recordset
'
' create local variables
Dim strDBName As String
Dim strRSName As String
Dim intRecs As Integer
Dim strFilter As String
'
' initialize the variables
strDBName = App.Path & "\..\data\books5.mdb"
strRSName = "Titles"
strFilter = "YearPub>1990"
'
' create the objects
Set db = DBEngine.OpenDatabase(strDBName)
Set rs = db.OpenRecordset(strRSName, dbOpenDynaset)
'
' count the records in the collection
rs.MoveLast ' move to end of list to force a count
intRecs = rs.RecordCount ' get count
MsgBox strRSName & " :" & CStr(intRecs), vbInformation, "Total Records in
Set"
'
' create filtered collection
rs.Filter = strFilter
Set rs2 = rs.OpenRecordset
'
End Sub |
|
|
|
|
|
|
|
|
Now that you've created the new Recordset from the old one, you can get a count of the selected records. You can add the same code you used earlier: Move to the end of the Recordset, get the RecordCount, and show it in a message box. Listing 3.7 shows the completed program. |
|
|
|
|
|